/**
 * 
 */
package com.oauth.global.server.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.gwtwidgets.server.spring.ServletUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.bind.annotation.RequestMapping;

import com.oauth.common.server.util.OAuthRequestUtil;
import com.oauth.global.server.service.GlobalOAuthService;
import com.oauth.service.members.beans.Member;

/**
 * @author asanthan
 * 
 */
@Controller
public class GlobalSpringController {

	@Autowired
	GlobalOAuthService globalOAuthService;

	@RequestMapping("/home/add")
	public void subscribe(HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ServletUtils.setRequest(request);
		ServletUtils.setResponse(response);
		Member member = OAuthRequestUtil.getMember(request);
		Long applicationId = ServletRequestUtils.getLongParameter(request, "id", 0l);
		if (applicationId != 0) {
			globalOAuthService.subscribe(member.getMemberId(), applicationId);
		}
		response.sendRedirect("/home?show=" + applicationId);
	}
}
